<!--经纪人奖励管理-详情-->
<template>
  <div class="brokerAwardDetail">
    <el-breadcrumb separator="/" class="bread-title">
      <el-breadcrumb-item :to="{ path: '/brokerAward' }">经纪人奖励管理</el-breadcrumb-item>
      <el-breadcrumb-item v-if="cash">查看详情</el-breadcrumb-item>
      <el-breadcrumb-item v-else>审核详情</el-breadcrumb-item>
    </el-breadcrumb>
    <list :awardInfoList="awardInfoList" :info="info" :brokerType="brokerType" :brokerPhone="brokerPhone"></list>
    <div v-if="cash" style="margin-bottom:25px">
      <div class="textTitle">操作记录</div>
      <el-table :data="RecordList" border style="width: 100%">
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <span>{{auditStatus(scope.row.auditStatus)}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="remark" label="备注"></el-table-column>
        <el-table-column align="center" prop="submitPersonName" label="操作人"></el-table-column>
        <el-table-column align="center" prop="createTime" label="操作时间">
          <template slot-scope="scope">
            <span>{{createTime(scope.row.createTime)}}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div v-else style="positon:relative">
      <div class="textTitle">审核意见</div>
      <el-input style="width:70%"  maxlength="200" type="textarea" :autosize="{ minRows: 3, maxRows: 7}" placeholder="请输入内容" v-model="reason"></el-input>
      <span class="resasonNum">{{reason.length}}/{{200 - reason.length}}</span>
      <el-button type="primary" @click="agree">同意</el-button>
      <el-button type="primary" @click="refuse">拒绝</el-button>
    </div>
  </div>
</template>
<script>
import list from "../../common/xkDetail";
import utils from '@/common/utils'
import api from '@/api/apiPath'
export default {
  name: "brokerAwardDetail",
  components: {
    list
  },
  data() {
    return {
      awardInfoList: [],
      info: {
        type: ''
      },
      RecordList: [],
      reason: "", // 审核意见
      cash: true,
      brokerType: '',
      brokerPhone: '' // 手机号
    };
  },
  created() {
    if(this.$route.query.cash == 1) {
      this.cash = false;
    }
    this.list(this.$route.query.id)
  },
  methods: {
    createTime(time) {
      return utils.getTimeString(time);
    },
    auditStatus(status) {
      if(status == 1) {
        return '待审核'
      }else if(status == 2) {
        return '运营审核通过'
      }else if(status == 3) {
        return '财务审核通过'
      }else if(status == 4) {
        return '运营审核拒绝'
      }else if(status == 5) {
        return '财务审核拒绝'
      }
    },
    list(id) {
      this.axios.get(api.audits + id).then(res => {
        if(res.data.code === 200) {
          this.info = res.data.data;
          this.awardInfoList = res.data.data.awardOrders;
          this.brokerType = res.data.data.awardOrders[0].brokerType.toString();
          this.brokerPhone = res.data.data.awardOrders[0].brokerPhone.toString();
        }
      })
      this.axios.get(api.agentRecord + id).then(res => {
        if(res.data.code === 200) {
          this.RecordList = res.data.data
        }
      })
    },
    req(num) {
      if (this.reason === "" && num === 1) {
        this.reason = "同意";
      } else if (this.reason === "" && num === 0) {
        this.reason = "拒绝";
      }
      let form = {auditStatus:num,applyId:this.info.id,reason:this.reason}
      this.axios.post(api.auditOpinions, form).then(res => {
        if(res.data.code === 200) {
          this.$message({
            type: 'success',
            message: '操作成功'
          })
          this.$router.push('./brokerAward')
        }
      })
    },
    // 同意
    agree() {
      this.req(1);
    },
    // 拒绝
    refuse() {
      this.req(0);
    }
  }
};
</script>
<style lang="stylus">
.brokerAwardDetail {
  .textTitle {
    line-height: 40px;
    font-weight: bold;
    margin-top: 15px;
    // position relative
  }
  .resasonNum {
    position relative
    bottom -8px
    right 60px
    color #666
  }
}
</style>

